﻿-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Dasideen_ResourceStat_Insert') 
    BEGIN
        DROP  PROCEDURE  Dasideen_ResourceStat_Insert
    END
GO

CREATE PROC [Dasideen_ResourceStat_Insert]
-- =============================================
-- Author:		<Sagar s.k>
-- Create date: <12/26/2014>
-- Description:	<Dasideen_ResourceStat_Insert>
-- =============================================
-- Add the parameters for the stored procedure here
	(
				
				@ResourceDescription varchar(1000),
				@ResourceTotalDownloads int,
 
				@Sys_CreatedByID varchar(50)= NULL,
				@Sys_ModifiedByID varchar(50) = NULL,
				@Sys_DeleteType int = 0,
				@Sys_OrganizationID int = NULL,
				@Sys_InitialPrimaryKeys varchar(max)= NULL,
				@Sys_WorkstationName varchar(50)= NULL,
				
				@Sys_DateOfCreation datetime OUTPUT,
				@ResourceKey int OUTPUT
	)
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
    SET NOCOUNT OFF 
	
	IF @Sys_WorkstationName = 'Default'	
	BEGIN
		SET @Sys_WorkstationName = (SELECT @@SERVERNAME);
	END
	DECLARE @CurrentDataTime datetime;
	SET @CurrentDataTime = GETDATE();

    INSERT INTO [ResourceStat]
            ( 
				[ResourceKey],
				[ResourceDescription] ,
				[ResourceTotalDownloads] ,
				[Sys_DateOfCreation] ,
				[Sys_DateOfModification] ,
				[Sys_CreatedByID] ,
				[Sys_ModifiedByID] ,
				[Sys_DeleteType] ,
				[Sys_IsDeleted] ,
				[Sys_OrganizationID] ,
				[Sys_InitialPrimaryKeys] ,
				[Sys_WorkstationName]
            )
	VALUES
			(  
				@ResourceKey,
                @ResourceDescription ,
                @ResourceTotalDownloads ,
                @CurrentDataTime ,
                @CurrentDataTime ,
                @Sys_CreatedByID ,
                @Sys_ModifiedByID ,
                @Sys_DeleteType ,
                0,
                @Sys_OrganizationID ,
                @Sys_InitialPrimaryKeys ,
                @Sys_WorkstationName
			);
	SET @ResourceKey = SCOPE_IDENTITY();
	SET @Sys_DateOfCreation = @CurrentDataTime;
END
GO